package com.imooc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: 顾志杰
 * @Date: 2019/11/15
 * @Time: 10:38
 */

@Configuration //需要让springboot扫描到
@EnableSwagger2 //开启swagger2配置
public class Swagger2 {

    /**
     *  地址 localhost:8088/swagger-ui.html
     *       localhost:8088/doc.html
     */



    // 配置swagger2核心配置 docket
    @Bean
    public Docket createRestApi(){
        // 置顶api类型为Swagger2
        return new Docket(DocumentationType.SWAGGER_2)
                // 用于定义api文档汇总信息
                .apiInfo(apiInfo())
                .select()
                //指定controller包
                .apis(RequestHandlerSelectors.basePackage("com.imooc.controller"))
                //所有controller
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                // 文档也标题
                .title("api接口")
                //联系人信息
                .contact(new Contact("梦魂"
                        ,"https://www.imooc.com"
                        ,"819162954@qq.com"))
                //详细信息
                .description("api文档")
                //版本号
                .version("1.0.1")
                //网址
                .termsOfServiceUrl("https://www.imooc.com")
                .build();
    }

}
